Everything Totally Explained


Ask & we'll explain, totally!
Template Attribute Language
Totally Explained


  NEW! All the latest news in the worlds of computer gaming, entertainment, the environment,  
finance, health, politics, science, stocks & shares, technology and much, much, more.  


View this entry using RSS

Everything about The Template Attribute Language totally explained

The Template Attribute Language (TAL) is a templating language aimed to generate HTML and XML pages. Its main goal is to simplify the collaboration of programmers and designers by templates being proper HTML (or XML, respectively) which can be worked on using common design tools.
   TAL was created for Zope but is used in other Python-based projects as well.

Overview

TAL Templates are often made from result pages with the variable content being replaced by special attributes; for example, <h1 tal:content="string:Some altogether different headline"> The headline visible to the designer </h1> would be treated by a common HTML design tool as <h1> The headline visible to the designer </h1> while the application server, evaluating the tal:content attribute, would yield <h1> Some altogether different headline </h1> Of course, string literals are not the most common nor the most useful use case; the syntax of the possible attribute values is property of the TAL Expression Syntax (TALES) language. In the Python-based implementations, it's for example possible to use Python expressions.
   Using METAL (Macro Expansion TAL) it's possible to re-use code from other templates.
   When generating XML documents, it's important to specify the XML namespace xmlns:tal="http://xml.zope.org/namespaces/tal"

Attributes

The following attributes are used, normally prefixed by "tal:":

define » creates local variables, valid in the element bearing the attribute (including contained elements)

; condition » decides whether or not to render the tag (and all contained text)

repeat » creates a loop variable and repeats the tag iterating a sequence, for example for creating a selection list or a table

; content » replaces the content of the tag

replace » replaces the tag (and therefore isn't usable together with content or attributes)

; attributes » replaces the given attributes (e. g. by using tal:attributes="name name; id name" the name and id attributes of an input field could be set to the value of the variable "name")

omit-tag » allows to omit the start and end tag and only render the content if the given expression is true.

; on-error » if an error occurs, this attribute works like the content tag.

If a tag has more than one TAL attributes, they're evaluated in the above (fairly logical) order.
   In cases when no tag is present which lends itself to take the attributes, special TAL tags can be used, making the "tal:" prefix optional. for example:
<tal:if condition="context/itemlist"> ...

</tal:if> would cause the code inside the tal:if tags to be used whenever the context (whatever the application server defines the context to be, for example an object) contains variable "itemlist" with a true value, for example a list containing at least one element. The identifier following the colon is arbitrary; it simply needs to be there, and to be the same for the opening and closing tag.

Usage

TAL/TALES/METAL are used by the following projects:

Other implementations

Besides the original Zope implementation, there are (not exhaustive):

Python

  • SimpleTAL (http://www.owlfish.com/software/simpleTAL/, TAL-guide)
  • OpenTAL (http://savannah.nongnu.org/projects/opental/)
  • ZPT (http://zpt.sourceforge.net/), a standalone version of Zope Page Templates

    Java

  • JPT: Java Page Templates (http://christophermrossi.com/jpt/)
  • JavaZPT (http://javazpt.sourceforge.net/)

    Perl

  • PETAL, the Perl Template Attribute Language (http://search.cpan.org/dist/Petal/)
  • Template-TAL (http://search.cpan.org/dist/Template-TAL/)

    PHP

  • PHPtal (http://phptal.motion-twin.com/)
  • PHPtal (http://phptal.pl/) - Polish site

    XSL

  • XSLTal, transforming TAL via XSL to XSLT; http://svn.bitflux.ch/repos/public/popoon/trunk/components/transformers/xsltal/tal2xslt.xslFurther Information

    Get more info on 'Template Attribute Language'.


    External Link Exchanges

    Do you know how hard it is to get a link from a large encyclopaedia? Well we're different and will prove it. To get a link from us just add the following HTML to your site on a relevant page:

      <a href="http://template_attribute_language.totallyexplained.com">Template Attribute Language Totally Explained</a>

    Then simply click through this link from your web page. Our crawlers will verify your link, extract the title of your web page and instantly add a link back to it. If you like you can remove the words Totally Explained and embed the link in article text.
       As long as your link remains in place, we'll keep our link to you right here. Please play fair - our crawlers are watching. Your site must be closely related to this one's topic. Any kind of spamming, dubious practises or removing the link will result in your link from us being dropped and, potentially, your whole site being banned.



  • Copyright © 2007-8 totallyexplained.com | Licensed under the GNU Free Documentation License | Site Map
    This article contains text from the Wikipedia article Template Attribute Language (History) and is released under the GFDL | RSS Version